package jse.test20160615.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.junit.Test;

/**
 * @desc  反射2
 * @author kanggw
 * @datetime 2016年6月21日,下午8:20:04
 */
public class Reflect2 {
	
	@Test
	public void test() throws ClassNotFoundException {
		
		Class<?> clazz = Class.forName("java.util.ArrayList");
		System.out.println("类的标准名称："+clazz.getCanonicalName());
		@SuppressWarnings("unchecked")
		Constructor[] constructors = clazz.getConstructors();
		System.out.println("类的构造方法");
		if(constructors.length != 0) {
			for(Constructor constructor : constructors) {
				System.out.println("\t"+constructor);//构造方法
			}
		}else {
			System.out.println("**");
		}
		
		Field[] fields = clazz.getDeclaredFields();
		System.out.println("类的非继承域变量");
		if(fields.length != 0) {
			for(Field field : fields) {
				System.out.println("\t"+field);//输出非继承域
			}
		} else {
			System.out.println("***");
		}
		
		Method[] methods = clazz.getMethods();
		System.out.println("类的非继承方法");
		if(methods.length != 0) {
			for(Method method : methods) {
				System.out.println("\t"+method);
			}
		}else {
			System.out.println("****");
		}
	}
}
